<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>会员中心</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .el-header{
            background-color: #9f7650;

        }
        .el-main{
            background-color: white;
            height: 488px;

        }
        .el-footer{background-color: blue}
        .el-aside{background-color: white}

        .el-button--goon.is-active,
        .el-button--goon:active {
            background: #d5a991;
            border-color: #d5a991;
            color: #fff;
        }
        .el-button--goon:focus,
        .el-button--goon:hover {
            background: #d5a991;
            border-color: #d5a991;
            color: #fff;
        }
        .el-button--goon {
            color: #FFF;
            background-color: #d5a991;
            border-color: #d5a991;
        }

    </style>
    <style>
        .el-menu-vertical-demo:not(.el-menu--collapse) {
            width: 200px;
            min-height: 400px;
        }
    </style>
</head>
<body>
<div id="app">

    <el-container>
        <el-header>
            <!--导航菜单开始-->
            <div style="background-color: #9f7650" >
                <el-menu style="width: 1200px;margin: 0 auto;border: 0" mode="horizontal" background-color="#9f7650"
                         text-color="#fff" active-text-color="#9f7650" >
                    <el-menu-item index=X1>房型信息</el-menu-item>
                    <el-menu-item index=X2>客户中心</el-menu-item>

                </el-menu>
            </div>
            <!--导航菜单结束-->
        </el-header>
        <el-container>
            <!--侧栏菜单开始-->
            <el-aside width="210px">
<!--                <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse"-->
<!--                         @select="handleSelect" :default-active="currentIndex">-->
                <el-card>
                    <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse"
                             @select="handleSelect" :default-active="currentIndex"
                             active-text-color="#9f7650"
                    >
                        <el-submenu index="1">
                            <template slot="title">
                                <i class="el-icon-tickets"></i>
                                <span slot="title">我的订单</span>
                            </template>
                            <el-menu-item-group>
                                <el-menu-item index="1-1">酒店预定</el-menu-item>
                                <el-menu-item index="1-2">我的订单</el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                        <el-submenu index="2">
                            <template slot="title">
                                <i class="el-icon-user"></i>
                                <span slot="title">我的账户</span>
                            </template>
                            <el-menu-item-group>
                                <el-menu-item index="2-1">个人信息</el-menu-item>
                                <el-menu-item index="2-2">信息修改</el-menu-item>
                                <el-menu-item index="2-3">账户安全</el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                        <el-menu-item index="3" >
                            <i class="el-icon-view"></i>
                            <span slot="title">关于会员</span>
                        </el-menu-item>
                    </el-menu>
                </el-card>
            </el-aside>
            <!--侧栏菜单结束-->
            <el-main>

                <!--预定房间 展示项开始-->
                <el-card v-if="currentIndex=='1-1'">
                    <h4>预定房间</h4>
                    <!--分割线-->
                    <el-divider></el-divider>
                    <!--分割线-->
                    <div>
                        <el-form ref="form" :model="form" label-width="150px">
                            <el-form-item label="入住时间" :span="11">

                                    <el-date-picker type="date" default-time="14:00:00" value-format="yyyy-MM-dd HH:mm:ss"
                                                    v-model="form.checkinDate" placeholder="选择入住日期"  style="width: 50%;">
                                    </el-date-picker>

                            </el-form-item>

                            <el-form-item label="退房时间" :span="11">
                                <el-date-picker type="date" default-time="13:00:00" value-format="yyyy-MM-dd HH:mm:ss" v-model="form.checkoutDate" placeholder="选择退房日期"  style="width: 50%;"></el-date-picker>
                            </el-form-item>


                            <el-form-item label="房间选择">
                                <el-select v-model="form.roomTypeId" placeholder="请选择房型">
                                    <el-option label="标准单间" value="1"></el-option>
                                    <el-option label="商务双人间" value="5"></el-option>
                                    <el-option label="豪华三人大房" value="9"></el-option>
                                </el-select>
                            </el-form-item>

                            <el-form-item label="联络人手机号">
                                <el-input v-model="form.contactTel"></el-input>
                            </el-form-item>

                            <el-form-item label="联络人性别" >
                                <el-radio-group v-model="form.gender" >
                                    <el-radio label="男" ></el-radio>
                                    <el-radio label="女" ></el-radio>
                                </el-radio-group>
                            </el-form-item>

                            <el-form-item label="联络人姓名">
                                <el-input v-model="form.contactName"></el-input>
                            </el-form-item>

                            <el-form-item label="随行人数">
                                <el-input v-model="form.visNum"></el-input>
                            </el-form-item>

                            <el-form-item label="特别备注">
                                <el-input type="textarea" v-model="form.note"></el-input>
                            </el-form-item>

                            <el-form-item>
                                <el-button type="goon"@click="onSubmit('form')">立即预定</el-button>
                                <el-button>取消</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </el-card>
                <!--预定房间展示项结束-->

                <!--我的订单 展示项开始-->
                <el-card v-if="currentIndex=='1-2'">
                    <h4>我的订单</h4>
                    <!--分割线-->
                    <el-divider></el-divider>
                    <!--分割线-->
                    <el-table :data="orderArr" >
                        <el-table-column type="index" label="编号" width="100"></el-table-column>
                        <el-table-column prop="bookDate" label="预订时间"  ></el-table-column>
                        <el-table-column prop="contactName" label="联系人"></el-table-column>
                        <el-table-column prop="contactTel" label="联系电话"></el-table-column>
                        <el-table-column prop="roomTypeName" label="预订房型"></el-table-column>
                        <el-table-column prop="visNum" label="随行人数"></el-table-column>
                        <el-table-column prop="checkinDate" label="入住时间"></el-table-column>
                        <el-table-column prop="checkoutDate" label="离店时间"></el-table-column>
                        <el-table-column prop="note" label="备注"></el-table-column>
                    </el-table>
                </el-card>
                <!--我的订单展示项结束-->

                <!--基本信息 展示项开始-->
                <el-card v-if="currentIndex=='2-1'">
                    <div align="center">
                        <el-descriptions title="基本信息">

                            <el-divider></el-divider>
                            <!--分割线-->
                            <el-descriptions-item label="用户ID">{{user.userId}}</el-descriptions-item>
                            <el-descriptions-item label="昵称">{{user.nickname}}</el-descriptions-item>
                            <el-descriptions-item label="性别">{{user.gender}}</el-descriptions-item>
                            <el-descriptions-item label="姓名" >{{user.userName}}</el-descriptions-item>
                            <el-descriptions-item label="身份证号">{{user.idNum}}</el-descriptions-item>
                            <el-descriptions-item label="手机号">{{user.tel}}</el-descriptions-item>

                        </el-descriptions>
                    </div>
                </el-card>
                <!--基本信息展示项结束-->

                <!--信息修改 展示项开始-->
                <el-card v-if="currentIndex=='2-2'">
                    <h4>更改信息</h4>
                    <div align="center">
                        <el-divider></el-divider>
                        <!--分割线-->

                        <div>
                            <el-form ref="editForm" :model="editForm" label-width="80px">

                                <el-form-item label="顾客昵称" >
                                    <el-input v-model="user.nickname" ></el-input>
                                </el-form-item>

<!--                                <el-form-item label="手机号码">-->
<!--                                    <el-input v-model="user.tel" value="666"></el-input>-->
<!--                                </el-form-item>-->

                                <el-form-item label="性别" >
                                    <el-radio-group v-model="user.gender" :value=user.gender >
                                        <el-radio label="男">男士</el-radio>
                                        <el-radio label="女">女士</el-radio>
                                    </el-radio-group>
                                </el-form-item>


                                <el-form-item label="顾客姓名">
                                    <el-input v-model="user.userName"></el-input>
                                </el-form-item>

                                <el-form-item label="身份证号">
                                    <el-input v-model="user.idNum"></el-input>
                                </el-form-item>

                                <el-form-item>
                                    <el-button type="goon"@click="onEditSubmit">更改</el-button>
                                    <el-button>取消</el-button>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </el-card>
                <!--信息修改展示项结束-->

                <!--账户安全修改 展示项开始-->
                <el-card v-if="currentIndex=='2-3'">
                    <h4>更改信息</h4>
                    <div align="center">
                        <el-divider></el-divider>
                        <!--分割线-->

                        <div>
                            <el-form ref="editForm" :model="editForm" label-width="80px">

                                <el-form-item label="顾客昵称" >
                                    <el-input v-model="user.nickname" ></el-input>
                                </el-form-item>

                                <el-form-item label="手机号码">
                                    <el-input v-model="user.tel" value="666"></el-input>
                                </el-form-item>

                                <el-form-item label="性别" >
                                    <el-radio-group v-model="user.gender" :value=user.gender >
                                        <el-radio label="男">男士</el-radio>
                                        <el-radio label="女">女士</el-radio>
                                    </el-radio-group>
                                </el-form-item>


                                <el-form-item label="顾客姓名">
                                    <el-input v-model="user.userName"></el-input>
                                </el-form-item>

                                <el-form-item label="身份证号">
                                    <el-input v-model="user.idNum"></el-input>
                                </el-form-item>

                                <el-form-item>
                                    <el-button type="goon"@click="onEditSubmit">更改</el-button>
                                    <el-button>取消</el-button>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </el-card>
                <!--账户安全展示项结束-->

                <!--关于会员展示项开始-->
                <el-card v-if="currentIndex=='3'">
                    <div align="center">
                        <el-empty description="当前页面正在开发中,敬请期待..."></el-empty>
                    </div>
                </el-card>
                <!--关于会员展示项结束-->

            </el-main>
        </el-container>
    </el-container>


</div>
</body>
<!-- import qs  不加脚手架可用qs.stringify -->
<script type="text/javascript" src="https://cdn.bootcss.com/qs/6.7.0/qs.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v =new Vue({
        el: '#app',
        data: function() {
            return {
                user:{},
                isLogin:false,
                currentIndex: "1-1",
                isCollapse: false,
                categoryArr: [{id:"1",name:"酒店信息"},{id:"2",name:"客户中心"}],

                form: {
                    roomTypeId: '',
                    checkinDate: '',
                    checkoutDate: '',
                    contactTel: '',
                    gender: '',
                    contactName: '',
                    visNum: '',
                    note: ''
                },
                editForm:{
                    sex:'',

                    gender:'',
                    userName:'',
                    idNum:''
                },
                formE:{

                },
                orderArr:[],

            }
        },
        methods:{
            handleSelect(key,keyPath){
                v.currentIndex=key;
                if((v.currentIndex=='2-1')||(v.currentIndex=='2-2')||(v.currentIndex=='2-3')){
                    console.log("开始展示用户信息请求,导航key:"+key);
                    this.displayInfo();
                }
                if(v.currentIndex=='1-2'){
                    console.log("开始展示订单请求,导航key:"+key);
                    this.listOrder();
                }

            },
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log(key, keyPath);
            },
            onSubmit() {
                console.log('点击了修改提交订单按钮!');

                let url='http://localhost:9080/orders/add-new'
                var qs = Qs;
                let formDataV=qs.stringify(v.form);
                console.log("v提交转化:"+formDataV);

                axios.post(url,formDataV).then(function (response) {
                    let responseBody=response.data;
                    console.log("state:"+responseBody.state);
                    console.log("message:"+responseBody.message);
                    if(responseBody.state==20000){

                        v.currentIndex='1-2';
                        console.log("跳到标签:"+v.currentIndex);
                    }else {
                        v.currentIndex='3';
                        console.log("跳到标签:"+v.currentIndex);
                    }
                });
            },
            onEditSubmit(){
                console.log('点击了修改提交按钮!');
                var qs = Qs;
                console.log("this.user:"+this.user);
                let editFormData=qs.stringify(this.user)
                console.log("editFormData:"+editFormData);
                //提交更改请求,不用RespondBody接收
                axios.post("/customercenter/update",editFormData);
            },
            displayInfo() {
                axios.get("/customercenter/info").then(function (response) {
                    let responseBody=response.data
                    console.log("状态码:"+responseBody.state);
                    console.log("对象信息:"+responseBody.data);
                    v.user=responseBody.data;
                    if(v.user==""){
                        alert("找不到相关用户信息,请稍后再试");
                        location.href="/login.html";
                    }
                })
            },
            onSubmitE() {
                console.log('submit!');
            },
            listOrder(){
                axios.get("/orders/orderList").then(function (response) {
                    console.log("对后端发送查找订单的请求！")
                    let d = response.data;
                    console.log(d)
                    v.orderArr=d.data;
                    console.log(v.orderArr)
                    console.log("已查询，赋值成功！")
                });
            }
        },
        created: function () {
            axios.get("/currentUser").then(function (response) {
                v.user=response.data;
                console.assert(v.user);
                if(v.user==""){
                    alert("您尚未登录，请登录！");
                    location.href="/login.html";
                }
            });

        }
    })
</script>
</html>